import { Inject, Injectable } from '@nestjs/common';
import * as svgCaptcha from 'svg-captcha';
import { RedisService } from '../redis/redis.service';
@Injectable()
export class SvgService {
  @Inject(RedisService)
  private redisService: RedisService;
  async sendSvg() {
    const captcha = svgCaptcha.create({
      ignoreChars: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
      size: 6, // 验证码长度
      noise: 1, // 干扰线条数目
    });
    // 图片验证码 文字
    const text = captcha.text;
    // 图片验证码
    const svg = captcha.data;
    await this.redisService.set(`svg_${text}`, captcha.text, 2 * 60);
    return svg;
  }
}
